package com.siwei.mes.entity.experiment.fineAggregate;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 细骨料-含泥量
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class FineAggregateHnl {
    @ApiModelProperty(value = "平均值")//1
    private String hnlpjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "色晕持续时间(min)1")
    private String sycxsj1;
    @ApiModelProperty(value = "加入亚甲蓝溶液总量")
    private String jryjlryzl;
    @ApiModelProperty(value = "亚甲蓝值")
    private String yjlz;
    @ApiModelProperty(value = "试验结论信息")
    private SyjgInfo syjgInfo = new SyjgInfo();
    @ApiModelProperty(value = "含泥量信息")
    private List<FineAggregateHnl.HnljzsInfo> hnljzsInfo = Collections.singletonList(new FineAggregateHnl.HnljzsInfo());

    @Data
    @Accessors(chain = true)
    @ApiModel("含泥量信息")
    public static class HnljzsInfo {
        @ApiModelProperty(value = "烘前试样质量")
        private String hqsyzl = "";
        @ApiModelProperty(value = "烘后试样质量")
        private String hhsyzl = "";
        @ApiModelProperty(value = "石粉质量")
        private String sfzl = "";
        @ApiModelProperty(value = "石粉含量")
        private String sfhl = "";
        @ApiModelProperty(value = "含泥量")
        private String hnl = "";
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("含泥量信息")
    public static class SyjgInfo {
        @ApiModelProperty(value = "色晕持续时间(min)1")
        private String sycxsj1;
        @ApiModelProperty(value = "色晕持续时间(min)2")
        private String sycxsj2;
        @ApiModelProperty(value = "色晕持续时间(min)3")
        private String sycxsj3;
        @ApiModelProperty(value = "色晕持续时间(min)4")
        private String sycxsj4;
        @ApiModelProperty(value = "色晕持续时间(min)5")
        private String sycxsj5;
        @ApiModelProperty(value = "色晕持续时间(min)6")
        private String sycxsj6;
        @ApiModelProperty(value = "色晕持续时间(min)7")
        private String sycxsj7;
        @ApiModelProperty(value = "色晕持续时间(min)8")
        private String sycxsj8;
        @ApiModelProperty(value = "试样质量")
        private String syzl = "";
        @ApiModelProperty(value = "加入亚甲蓝溶液体积(ml)1")
        private String jryjlrytj1 = "";
        @ApiModelProperty(value = "加入亚甲蓝溶液体积(ml)2")
        private String jryjlrytj2 = "";
        @ApiModelProperty(value = "加入亚甲蓝溶液体积(ml)3")
        private String jryjlrytj3 = "";
        @ApiModelProperty(value = "加入亚甲蓝溶液体积(ml)4")
        private String jryjlrytj4 = "";
        @ApiModelProperty(value = "加入亚甲蓝溶液体积(ml)5")
        private String jryjlrytj5 = "";
        @ApiModelProperty(value = "加入亚甲蓝溶液体积(ml)6")
        private String jryjlrytj6 = "";
        @ApiModelProperty(value = "加入亚甲蓝溶液体积(ml)7")
        private String jryjlrytj7 = "";
        @ApiModelProperty(value = "加入亚甲蓝溶液体积(ml)8")
        private String jryjlrytj8 = "";
        @ApiModelProperty(value = "MB值")
        private String mbz = "";
        @ApiModelProperty(value = "单项结论")
        private String dxjl = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        FineAggregateHnl entity = new FineAggregateHnl();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, FineAggregateHnl.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, FineAggregateHnl.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        FineAggregateHnl entity = JsonUtils.getObject(objJson, FineAggregateHnl.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getHnlpjz()) || "null".equals(entity.getHnlpjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValueHnl(FineAggregateHnl entity, Map<String, Object> data) {
        List<FineAggregateHnl.HnljzsInfo> hnljzsInfo = new ArrayList<>();
        HnljzsInfo hnljzsInfoOne = new HnljzsInfo();
        if(data.get("S1") != null){
            hnljzsInfoOne.setHqsyzl(data.get("S1").toString());
        }
        if(data.get("S2") != null){
            hnljzsInfoOne.setHhsyzl(data.get("S2").toString());
        }
        if(data.get("S3") != null){
            hnljzsInfoOne.setHnl(data.get("S3").toString());
        }
        hnljzsInfo.add(hnljzsInfoOne);
        HnljzsInfo hnljzsInfoTwo = new HnljzsInfo();
        if(data.get("S4") != null){
            hnljzsInfoTwo.setHqsyzl(data.get("S4").toString());
        }
        if(data.get("S5") != null){
            hnljzsInfoTwo.setHhsyzl(data.get("S5").toString());
        }
        if(data.get("S6") != null){
            hnljzsInfoTwo.setHnl(data.get("S6").toString());
        }
        hnljzsInfo.add(hnljzsInfoTwo);
        if(data.get("S7") != null){
            entity.setHnlpjz(data.get("S7").toString());
        }
        entity.setHnljzsInfo(hnljzsInfo);
    }

    public static void setValueYjl(FineAggregateHnl entity, Map<String, Object> data) {
        FineAggregateHnl.SyjgInfo syjgInfo = entity.getSyjgInfo();
        if(data.get("S2") != null){
            syjgInfo.setSyzl(data.get("S2").toString());
        }
        if(data.get("S3") != null){
            entity.setJryjlryzl(data.get("S3").toString());
        }
        if(data.get("S4") != null){
            entity.setYjlz(data.get("S4").toString());
        }
        if(data.get("S5") != null){
            syjgInfo.setJryjlrytj1(data.get("S5").toString());
        }
        if(data.get("S6") != null){
            syjgInfo.setJryjlrytj2(data.get("S6").toString());
        }
        if(data.get("S7") != null){
            syjgInfo.setJryjlrytj3(data.get("S7").toString());
        }
        if(data.get("S8") != null){
            syjgInfo.setJryjlrytj4(data.get("S8").toString());
        }
        if(data.get("S9") != null){
            syjgInfo.setJryjlrytj5(data.get("S9").toString());
        }
        if(data.get("S10") != null){
            syjgInfo.setJryjlrytj6(data.get("S10").toString());
        }
        if(data.get("S11") != null){
            syjgInfo.setJryjlrytj7(data.get("S11").toString());
        }
        if(data.get("S12") != null){
            syjgInfo.setJryjlrytj8(data.get("S12").toString());
        }

        if(data.get("S15") != null){
            syjgInfo.setSycxsj1(data.get("S15").toString());
        }
        if(data.get("S16") != null){
            syjgInfo.setSycxsj2(data.get("S16").toString());
        }
        if(data.get("S17") != null){
            syjgInfo.setSycxsj3(data.get("S17").toString());
        }
        if(data.get("S18") != null){
            syjgInfo.setSycxsj4(data.get("S18").toString());
        }
        if(data.get("S19") != null){
            syjgInfo.setSycxsj5(data.get("S19").toString());
        }
        if(data.get("S20") != null){
            syjgInfo.setSycxsj6(data.get("S20").toString());
        }
        if(data.get("S21") != null){
            syjgInfo.setSycxsj7(data.get("S21").toString());
        }
        if(data.get("S22") != null){
            syjgInfo.setSycxsj8(data.get("S22").toString());
        }

        if(data.get("S25") != null){
            entity.setSycxsj1(data.get("S25").toString());
        }
        if(data.get("S26") != null){
            syjgInfo.setDxjl(data.get("S26").toString());
        }

        List<FineAggregateHnl.HnljzsInfo> hnljzsInfo = new ArrayList<>();
        HnljzsInfo hnljzsInfoOne = new HnljzsInfo();
        if(data.get("S27") != null){
            hnljzsInfoOne.setHqsyzl(data.get("S27").toString());
        }
        if(data.get("S28") != null){
            hnljzsInfoOne.setHhsyzl(data.get("S28").toString());
        }
        if(data.get("S29") != null){
            hnljzsInfoOne.setSfhl(data.get("S29").toString());
            hnljzsInfoOne.setSfzl(data.get("S29").toString());
        }
        hnljzsInfo.add(hnljzsInfoOne);
        HnljzsInfo hnljzsInfoTwo = new HnljzsInfo();
        if(data.get("S30") != null){
            hnljzsInfoTwo.setHqsyzl(data.get("S30").toString());
        }
        if(data.get("S31") != null){
            hnljzsInfoTwo.setHhsyzl(data.get("S31").toString());
        }
        if(data.get("S32") != null){
            hnljzsInfoTwo.setSfhl(data.get("S32").toString());
            hnljzsInfoTwo.setSfzl(data.get("S32").toString());
        }
        hnljzsInfo.add(hnljzsInfoTwo);
        if(data.get("S33") != null){
            entity.setHnlpjz(data.get("S33").toString());
        }
        entity.setHnljzsInfo(hnljzsInfo);
    }
}
